package com.salim.leetcode.$49;

import java.util.*;

public class GroupAnagrams {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> resultMap = new HashMap<>();
        for(int i=0;i<strs.length;i++){
            char[] car=strs[i].toCharArray();
            Arrays.sort(car);
            String key=new String(car);
            if(resultMap.containsKey(key)){
                resultMap.get(key).add(strs[i]);
            }else{
                List<String> subResultList = new ArrayList<>();
                subResultList.add(strs[i]);
                resultMap.put(key,subResultList);
            }
        }
        List<List<String>> result = new ArrayList<>();
        for (Map.Entry<String, List<String>> entry : resultMap.entrySet()) {
            result.add(entry.getValue());
        }
        return result;
    }

    public static void main(String[] args) {
        GroupAnagrams fun = new GroupAnagrams();
        fun.groupAnagrams(new String[]{"bdddddddddd", "bbbbbbbbbbc"});
    }
}
